package com.swu.pad.experiment.service.impl;

import java.sql.ResultSet;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.TreeMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import com.swu.pad.activity.dao.ActivityDao;
import com.swu.pad.activity.entity.Activity;
import com.swu.pad.assignment.dao.AssignmentDao;
import com.swu.pad.assignment.dao.AssignmentPadDao;
import com.swu.pad.assignment.entity.Assignment;
import com.swu.pad.assignment.entity.AssignmentPad;
import com.swu.pad.assignment.service.AssignmentPadService;
import com.swu.pad.assignment.service.AssignmentService;
import com.swu.pad.comment.dao.CommentDao;
import com.swu.pad.comment.dao.CommentQuestionDao;
import com.swu.pad.comment.dao.ConnectDatabase;
import com.swu.pad.comment.dao.FbCommentDao;
import com.swu.pad.comment.dao.FbCommentGradeDao;
import com.swu.pad.comment.entity.Comment;
import com.swu.pad.comment.entity.CommentQuestion;
import com.swu.pad.comment.entity.FbComment;
import com.swu.pad.comment.entity.FbCommentGrade;
import com.swu.pad.course.dao.CourseDao;
import com.swu.pad.course.dao.CourseGroupUserDao;
import com.swu.pad.course.dao.GroupDao;
import com.swu.pad.course.dto.Student;
import com.swu.pad.course.entity.Course;
import com.swu.pad.course.entity.CourseGroupUser;
import com.swu.pad.course.service.CourseService;
import com.swu.pad.event.dao.EventDao;
import com.swu.pad.event.entity.Event;
import com.swu.pad.experiment.service.ExperimentService;
import com.swu.pad.reflection.dao.ModifiedSentenceDao;
import com.swu.pad.reflection.dao.ReflectionFbItemDao;
import com.swu.pad.reflection.dao.RftFbItemScoreDao;
import com.swu.pad.reflection.dao.SentenceClassDao;
import com.swu.pad.reflection.entity.ModifiedSentence;
import com.swu.pad.reflection.entity.RftFbItemScore;
import com.swu.pad.reflection.entity.RftFeedbackItem;
import com.swu.pad.reflection.entity.SentenceClass;
import com.swu.pad.reflection.service.ReflectionService;
import com.swu.pad.system.dao.UserDao;
import com.swu.pad.system.entity.User;
import com.swu.pad.system.entity.Users;
import com.swu.pad.system.service.UserService;
import com.swu.pad.util.DocToSentencesClassUtil;
import com.swu.pad.util.StringUtil;
import com.swu.pad.util.TimeUtil;
import com.swu.pad.util.EPLiteClient.EPLiteClient;

import java_cup.internal_error;
@Service
@Transactional
public class ExperimentServiceImpl implements ExperimentService {
	
	
	@Autowired
	private AssignmentPadService assignmentPadService;
	@Autowired
	private ActivityDao activityDao;
	@Autowired
	private UserService userService;
	@Autowired
	private AssignmentDao assignmentDao;
	@Autowired
	private AssignmentPadDao assignmentPadDao;
	@Autowired
	private CourseGroupUserDao courseGroupUserDao;
	@Autowired
	private CommentDao commentDao;
	@Autowired
	private CommentQuestionDao commentQuestionDao;
	@Autowired
	private AssignmentService assignmentService;
	@Autowired
	private CourseService courseService;
	@Autowired
	private GroupDao groupDao;
	@Autowired
	private EPLiteClient epliteClient;
	@Autowired
	private FbCommentDao fbCommentDao;
	@Autowired
	private UserDao userDao;
	@Autowired
	private FbCommentGradeDao fbCommentGradeDao;
	@Autowired
	private EventDao eventDao;
	@Autowired
	private ReflectionService reflectionService;
	@Autowired
	private SentenceClassDao stcDao;
	@Autowired
	private ReflectionFbItemDao rftFbItemDao;
	@Autowired
	private RftFbItemScoreDao rftFbItemScoreDao;
	@Autowired
	private ModifiedSentenceDao modifiedSentenceDao;
	@Autowired
	private SentenceClassDao sentenceClassDao;
	@Autowired
	private CourseDao courseDao;
	

	public List<Map<String,Object>> getCourseReplyInfo(String activityId, String courseId) {
		
	if(activityId!=null&&courseId!=null&&(!activityId.equals(""))&&(!courseId.equals(""))){
	       List<Student> students=courseService.getStudents(courseId);
	       List<Map<String,Object>> dataList=new ArrayList<Map<String,Object>>();	 
	       Activity activity=activityDao.findActivityById(activityId);	      
		   Assignment assignment=assignmentDao.findAssignmentById(activity.getAssignmentId());		 
		   List<CommentQuestion> commentQuestions=commentQuestionDao.findByTemplateId(assignment.getReplyTemplateId());		 
	       List<String> questionList=new ArrayList<String>();
	       for (int i = 0; i < commentQuestions.size(); i++) {
			questionList.add(commentQuestions.get(i).getQuestion());
		   }
		   Map<String,Object> questionMap=new HashMap<String, Object>();
	       questionMap.put("commentQuestions", questionList);
	     
		   dataList.add(questionMap);
  if(students.size()>0){
	 for(int y=0;y<students.size();y++){
		String username=students.get(y).getStudentNum();
		if(activityId!=null&&username!=null&&(!activityId.equals(""))&&(!username.equals(""))){
		Map<String,Object> map=new HashMap<String, Object>();
		int eventCount=0;
		String userId="";
		String userName="";
		int noFbCount=0;
	    List<User> users=userDao.findUserByUsername(username);
	   
	    for (int i = 0; i <users.size(); i++) {
	     List<CourseGroupUser> lists=courseGroupUserDao.findCourseGroupUserByUserId(users.get(i).getId());
	      for (int j = 0; j < lists.size(); j++) {
			if(lists.get(j).getCourseId().equals(assignment.getCourseId())){
				userId=lists.get(j).getUserId();
				userName=lists.get(j).getUserName();
			}
		  } 	
		}
	    //插入姓名
	    map.put("userName",userName);
	    //插入学号
	    map.put("stuNum",students.get(y).getStudentNum());
	    //小组作业组号
	    map.put("groupNum", students.get(y).getGroupNum());
	    //小组作业互评组号
	    map.put("commentGroupNum",students.get(y).getCommentGroupNum());
	    //个人作业编号
	    map.put("singleNum",students.get(y).getSingleNum());
	    //个人作业互评号
	    map.put("commentSingleNum",students.get(y).getCommentSingleNum());
	    //邮箱
	    map.put("email",students.get(y).getEmail());
	    //用户给出评论总条数
	    List<FbComment> addCommentList=fbCommentDao.findFbCommentByAuthorIdAndFeedbackTypeAndActivityId(userId,"0",activityId);
	    //插入反馈总数
	    map.put("addCommentNum",addCommentList.size());
	    for (int i = 0; i <addCommentList.size(); i++) {
			List<FbComment> tempList=fbCommentDao.findFbCommentByCommentIdAndFeedbackType(addCommentList.get(i).getCommentId(),"grade");
		    if(tempList.size()>0){
		    	noFbCount=noFbCount+1;
		    }
	    }
	    noFbCount=addCommentList.size()-noFbCount;
	    map.put("noFbCount",noFbCount);
	    //先算总分，注意时间戳。
	    int score=0;
	    for (int i = 0; i < addCommentList.size(); i++) {
	    	List<FbComment> tempList=fbCommentDao.findFbCommentByCommentIdAndFeedbackType(addCommentList.get(i).getCommentId(),"grade");
	    	if(tempList.size()>0){
	    	String compareDate="";
	    	int index=0;
	    	for (int j = 0; j < tempList.size(); j++) {//找到最新的
			      if(compareDate.compareTo(tempList.get(j).getTimestamp())<=0){
			    	  compareDate=tempList.get(j).getTimestamp();
			    	  index=j;
			         }
			    }
	        int fbid=tempList.get(index).getId();
	        List<FbCommentGrade> fbGradeList=fbCommentGradeDao.findFbCommentByFbid(Integer.toString(fbid));
	        if(fbGradeList.size()>0){
	        	for (int j = 0; j<fbGradeList.size(); j++) {
					 score+=Integer.parseInt(fbGradeList.get(j).getScore());
				}
	        	
	        }//本条有回复的分数加算完毕
	      }//本条有回复的add计算结束
	       else{//说明这条add没有回复
	    	   score+=0;
	       }
		}
	    //插入总分
	    if(score==0){
	    	map.put("totalScore","0");
	    }else{
	    	map.put("totalScore",score);
	    }
	    //每个类别的得分，先拿模板跟评论维度
	   
	    List<Map<String,Object>> listMap=new ArrayList<Map<String,Object>>();//存维度加总分的lsit
	    if(commentQuestions.size()>0){
	     for (int k = 0; k < commentQuestions.size(); k++) {
	    	 int dimScore=0; 
	    	 int dimCount=0;
	    	 Map<String, Object> tempMap=new HashMap<String, Object>();//‘维度名称’‘总分
		      for (int i = 0; i < addCommentList.size(); i++) {
		    	List<FbComment> tempList=fbCommentDao.findFbCommentByCommentIdAndFeedbackType(addCommentList.get(i).getCommentId(),"grade");
		    	if(tempList.size()>0){//说明有回复
		    	String compareDate="";
		    	int index=0;
		    	for (int j = 0; j < tempList.size(); j++) {//找到最新的
				      if(compareDate.compareTo(tempList.get(j).getTimestamp())<=0){
				    	  compareDate=tempList.get(j).getTimestamp();
				    	  index=j;
				         }
				    }
		    	
		        int fbid=tempList.get(index).getId();
		        List<FbCommentGrade> fbGradeList=fbCommentGradeDao.findFbCommentByFbid(Integer.toString(fbid));
		        
		        for (int j = 0; j <fbGradeList.size(); j++) {
				    if(fbGradeList.get(j).getFeedback().equals(commentQuestions.get(k).getQuestion())){
				        dimScore+=Integer.parseInt(fbGradeList.get(j).getScore());	  
				        dimCount++;
				    }
				}
               		        
		    	}
	       }
		      
		      map.put(commentQuestions.get(k).getQuestion()+"的次数",Integer.toString(dimCount));
		      map.put(commentQuestions.get(k).getQuestion(),Integer.toString(dimScore));
//	       tempMap.put(commentQuestions.get(k).getQuestion(),Integer.toString(dimScore)); 
	       listMap.add(tempMap);
	      }//维度循环结束标志  
	    }else{
	    	System.out.println("根据reply模板id没有拿到反馈问题！");
	    }
	    //插入维度得分
//	    map.put("dimScore",listMap);
	    //event使用情况
	    
	    List<Event> eventList=eventDao.findEventByUserId(userId); 
	    for (int i = 0; i <eventList.size(); i++) {
			String action=eventList.get(i).getObject();
			String[] sub=action.split("-");
		    if(sub.length>0){
		    	if(sub[0].equals(activityId)){
		    		eventCount+=1;
		    	}
		    }
		}
	    map.put("clickNumOfEvent",eventCount);
	   
        dataList.add(map);  
	  }
	   else{ 
		   System.out.println("ExperimentServiceImpl---接收的学生学号或者activityId有空值！");
           
		}
		//上午结束
		
	   }
	     return dataList;
	 } 
	 else{
		   System.out.println("ExperimentServiceImpl---没有拿到班级所有学生！"); 
	   }
		 
	}
       	return null;
     
}

//全班的版本
	@Override
	public Map getAllAssVersion( String assignmentId) {
		Map map=new HashMap();
		JSONArray versions=new JSONArray();
		Assignment assignment =assignmentDao.findAssignmentById(assignmentId);
		String courseId=assignment.getCourseId();
		List courses=courseGroupUserDao.findCourseGroupUserByCourseId(courseId);
		Iterator it=courses.iterator();
		List<Users> users =new ArrayList<Users>();
         while(it.hasNext()){
        	 CourseGroupUser c=(CourseGroupUser) it.next();
//        	 List versionAll=new ArrayList();
        		JSONObject jsono= assignmentPadService.getVersion(c.getGroupName(),assignmentId);
//        		 jsono= assignmentPadService.getVersion(c.getGroupName(),assignmentId);
//        		 if(jsono.get("version")!=null){
//        	     List list=(List) jsono.get("version");
//        		 versionAll.addAll(list);
//        		 }
        		 jsono= assignmentPadService.getVersion(c.getGroupName(),assignmentId);
        		 jsono= assignmentPadService.getVersion(c.getGroupName(),assignmentId);
        		 jsono= assignmentPadService.getVersion(c.getGroupName(),assignmentId);
//        		 if(jsono.get("version")!=null){
//        		 List list=(List) jsono.get("version");
//        		 versionAll.addAll(list);     
//        		 }
        		if(jsono.get("version")!=null){
        	   
        		JSONArray _version=jsono.getJSONArray("version");
        		versions.addAll(_version);
        		Users user=new Users();
        		user.setName(c.getUserName());
        		user.setId(c.getUserId());
        		users.add(user);
        		}
        		
        		
        		/*
        		 * 组装其他行为数据
        		 */
        		List data=getUserVersion(c.getUserId(),assignmentId);
        		if(data != null){
        			versions.addAll(data);
        		}
        		
         }
         //放入全班的版本号
         map.put("versions", versions);
         map.put("user", users);
         return map;
         
	}
/**
 * 获取一个学生的操作信息
 */
	@Override
	public List getUserVersion(String userId,String assignmentId) {
		List datas=new ArrayList();
		List<Event> events=eventDao.findEventByUserId(userId);
		Iterator it=events.iterator();
		  while(it.hasNext()){
			  Map map=new HashMap();
			  Event event=(Event)it.next();
			  String actId=event.getObject().toString().split("-")[0];
			  Activity activity=activityDao.findActivityById(actId);	      
			  Assignment assignment=assignmentDao.findAssignmentById(activity.getAssignmentId());
			  if(assignment.getId().equals(assignmentId)){
			  map.put("author",userId);
			  map.put("cmd", "see");
			  map.put("timestamp", TimeUtil.toTimes(event.getActionTime().toString()));
			  datas.add(map);
			  }
		  }
		  List<FbComment> commentList=fbCommentDao.findFbCommentByAuthorIdAndFeedbackTypeAndAssignmentId(userId, "0",assignmentId);
		  Iterator it2=commentList.iterator();
		  while(it2.hasNext()){
			  Map map=new HashMap();
			  FbComment fbcomment=(FbComment)it2.next();
			  map.put("author", userId);
			  map.put("cmd", "comment");
			  map.put("timestamp", Long.parseLong(fbcomment.getTimestamp()));
			  datas.add(map);
		  }
		  List<FbComment> gradeList=fbCommentDao.findFbCommentByCommenterIdAndFeedbackTypeAndAssignmentId(userId,"grade",assignmentId);
		  Iterator it3=gradeList.iterator();
		  while(it3.hasNext()){
			  Map map=new HashMap();
			  FbComment fbcomment=(FbComment)it3.next();
			  map.put("author", userId);
			  map.put("cmd", "grade");
			  map.put("timestamp", Long.parseLong(fbcomment.getTimestamp()));
			  datas.add(map);
		  }
		  
		  List<FbComment> ReplyList=fbCommentDao.findFbCommentByCommenterIdAndFeedbackTypeAndAssignmentId(userId,"Reply",assignmentId);
		  Iterator it4=ReplyList.iterator();
		  while(it4.hasNext()){
			  Map map=new HashMap();
			  FbComment fbcomment=(FbComment)it4.next();
			  map.put("author", userId);
			  map.put("cmd", "reply");
			  map.put("timestamp", Long.parseLong(fbcomment.getTimestamp()));
			  datas.add(map);
		  }
		
		return  datas;
	}

	@Override
	public List<Map<String, Object>> getCommentText(String activityId,
			String courseId) {
		 List<Map<String,Object>> dataList=new ArrayList<Map<String,Object>>();
		if(activityId!=null&&courseId!=null&&(!activityId.equals(""))&&(!courseId.equals(""))){
			List<Student> students=courseService.getStudents(courseId);
		  
			Iterator stus=students.iterator();
			while(stus.hasNext()){
				Student student=(Student) stus.next();			
				String id=student.getUserId();
				String name=student.getName();
				String stunum=student.getStudentNum();			
				List data=getUserCommentText(student.getUserId(),activityId);
				Iterator it =data.iterator();
				while(it.hasNext()){
					Map<String,Object> map=new LinkedHashMap<String, Object>();
					Map grade=(Map)it.next();
					map.put("name", name);
					map.put("stunum", stunum);
					map.put("type", (grade.get("type")));
					map.put("score", (grade.get("score")));
					String text_=grade.get("text")+"";
					//去除内容中的换行符等乱码字符
					map.put("text", StringUtil.replace(text_));	
					User commenter=userDao.findUserById(grade.get("commenterId")+"");
					if(commenter!=null){
					map.put("commenterName", commenter.getRealname());	
					}else{
					map.put("commenterName", "已删除的评论");
					}
					dataList.add(map);
				}
				
			}
		}
		return dataList;
	}

	@Override
	public List getUserCommentText(String userId, String activityId) {
		List datas =new ArrayList();
		List<FbComment> commentList=fbCommentDao.findFbCommentByAuthorIdAndFeedbackTypeAndActivityId(userId, "0",activityId);
		  Iterator it2=commentList.iterator();
		  while(it2.hasNext()){
			  Map map=new HashMap();
			  FbComment fbcomment=(FbComment)it2.next();
			  map.put("text", fbcomment.getCommentText());
			  map.put("commenterId", fbcomment.getCommenterId());
			  List<FbComment> id=fbCommentDao.findFbCommentByCommentIdAndFeedbackTypeAndActivityId(fbcomment.getCommentId(),"grade",activityId);	
			  if(id.size()>0){
			  List<FbCommentGrade> grades=fbCommentGradeDao.findFbCommentByFbid(id.get(0).getId()+"");
			  if(grades.size()>0){
			  map.put("type", grades.get(0).getFeedback());
			  map.put("score", grades.get(0).getScore());
			  }
			  }else{
				  map.put("type", "未收到回复");
				  map.put("score", 0);  
			  }
			  datas.add(map);
		  }
		  return datas;
	}
     
	//获取 班级 组内 互评数据
	@Override
	public List<Map<String, Object>> getCourseGroupCommentInfo(String activityId, String courseId) {
		//1 获取班级所有 用户，和评论 的 6个维度 
		//5e46fe7262f6e9ca0162fa9b5a7d00cd-----5e46fe7262f6e9ca0162f7f59baf00b1  2018 教育数据分析
		if(activityId!=null&&courseId!=null&&(!activityId.equals(""))&&(!courseId.equals(""))){
		       List<Student> students=courseService.getStudents(courseId);
		       List<Map<String,Object>> dataList=new ArrayList<Map<String,Object>>();	 
		       Activity activity=activityDao.findActivityById(activityId);	
		       Date endTime=activity.getEndDate();
		       Date startTime=activity.getStartDate();
			   Assignment assignment=assignmentDao.findAssignmentById(activity.getAssignmentId());	
			   List<CommentQuestion> commentQuestions=commentQuestionDao.findByTemplateId(assignment.getMutualTemplateId());		 
//		       List<String> questionList=new ArrayList<String>();
//		       for (int i = 0; i < commentQuestions.size(); i++) {
//				questionList.add(commentQuestions.get(i).getQuestion());
//			   }
//			   Map<String,Object> questionMap=new HashMap<String, Object>();
//		       questionMap.put("commentQuestions", questionList);
//			   dataList.add(questionMap);
			//2 根据 所有用户遍历  每次每个人 在每个维度上的最新得分
			
			   if(students.size()>0){
					 for(int y=0;y<students.size();y++){
						String studentNum=students.get(y).getStudentNum();
						Map<String,Object> map=new HashMap<String, Object>();//用来封装 一个学生的 所有维度得分和 学生个人信息 数据
						if(studentNum!=null&&(!studentNum.equals(""))){
						
						String userName="";
						String userId="";
						List<User> users=userDao.findUserByUsername(studentNum);
						   
						    for (int i = 0; i <users.size(); i++) {
						     List<CourseGroupUser> lists=courseGroupUserDao.findCourseGroupUserByUserId(users.get(i).getId());
						      for (int j = 0; j < lists.size(); j++) {
								if(lists.get(j).getCourseId().equals(assignment.getCourseId())){
									userName=lists.get(j).getUserName();
									userId=lists.get(j).getUserId();//当前 学生的id
								}
							  } 	
							}
						    
						   //保存学号
						   map.put("studentNum",studentNum);
						   //保存姓名
						   map.put("userName",userName);
						   //小组作业组号
						   map.put("groupNum", students.get(y).getGroupNum());
						   //小组作业互评组号
						   // map.put("commentGroupNum",students.get(y).getCommentGroupNum());
						   //3 for 维度    for(组员 一次 ){ for 评论  == 最新的   维度分数替换} --某个维度上的得分     
						   List<CourseGroupUser> groupUsers=courseGroupUserDao.findCourseGroupUserByCourseIdAndGroupName(courseId,"小组"+ students.get(y).getGroupNum());
						   AssignmentPad assignmentPad=assignmentPadDao.findAssignmentPadByGroupNameAndAssignmentId("小组"+ students.get(y).getGroupNum(),assignment.getId());

						   //根据评论维度做循环
						   for (int i = 0; i < commentQuestions.size(); i++) {
							//找出  当前学生 在这次 作业中 所有的 被打分 记录
							   Double totalScore=0.0;//维度总得分
							   Double result=0.0;
							for (int j = 0; j < groupUsers.size(); j++) {
								
								if(groupUsers.get(j).getUserId()!=userId){//不是本人
				                List<Comment> comments=commentDao.findByAssignmentPadIdAndAuthorIdAndCommenterIdAndQuestionId(assignmentPad.getId(),userId,groupUsers.get(j).getUserId(),commentQuestions.get(i).getId());
				                String score="0";//某个组员 给当前学生 在某个 维度的打分
				                
				                if(comments.size()>0){
				                Date maxTime=comments.get(0).getCommentTime();
				                score=comments.get(0).getScore();
				                for (int k = 0; k < comments.size(); k++) {
				                	//commentTime=2018-05-06 11:18:10.0,
				                	if((comments.get(k).getCommentTime().compareTo(endTime)<=0)&&(comments.get(k).getCommentTime().compareTo(startTime)>=0)){
				                		//卡 进 当前活动日期
				                          if(comments.get(k).getCommentTime().compareTo(maxTime)>=0){
				                        	  maxTime=comments.get(k).getCommentTime();
				                        	  score=comments.get(k).getScore();//最新的分数
				                          }
				                          
				                	}
								}
				                }//if end
				                totalScore+=Double.valueOf(score);
								}
							
							}
							result=totalScore/(groupUsers.size()-1);
							result = (double)Math.round(result*100)/100;
							//放入键位和分数
							//{信任感=3.75, 友好度=3.75, 工作数量=3.5, 工作质量=3.75, groupNum=6, userName=彭琰, 团队合作能力=3.75, studentNum=222016321081017, 影响力=3.5}
							
//						  System.out.println(map.toString());
							if(commentQuestions.get(i).getQuestion().equals("信任感")){
								map.put("xinren",result);
							}else if(commentQuestions.get(i).getQuestion().equals("友好度")){
								map.put("youhao",result);
							}else if(commentQuestions.get(i).getQuestion().equals("工作数量")){
								map.put("shuliang",result);
							}else if(commentQuestions.get(i).getQuestion().equals("工作质量")){
								map.put("zhiliang",result);
							}else if(commentQuestions.get(i).getQuestion().equals("团队合作能力")){
								map.put("tuandui",result);
							}else if(commentQuestions.get(i).getQuestion().equals("影响力")){
								map.put("yingxiang",result);
							}else {
								System.out.println("获取班级组内互评数据，学生填充维度得分时，没有相应维度！");
							}
						   
						   
						   }
						   
						}else{
							System.out.println("获取班级组内互评数据有问题，学生学号有空!");
						}
						dataList.add(map);  
					 }//遍历整个班级学生结束
					return dataList;
			   }else{
				   System.out.println("获取班级 组内互评数据，根据班级id获得学生为空！没有获取到一个学生！ ");
			   }
		} else{
			System.out.println("获取班级组内互评数据出现问题,activityid或者courseid为空！");
		}
		

		return null;
	}
   
	//获得班级 某次作业下同学们的反思写作参考分数 ，在前端导出为excel表
	/*
	 * @Override public Map<String, Object> getCourseRftAsmtRferScores(Assignment
	 * assignment) throws Exception {
	 * //reflectionService.querySentences(padId,activityId,user)所有信息 //1列出所有 班级学生
	 * 查询条件 班级id 小组类型 1 （代表个人作业）| 因为本功能针对反思写作，反思写作作业都是个人作业 List<CourseGroupUser>
	 * courseStudents=courseGroupUserDao.findCourseGroupUserByCourseIdAndGroupType(
	 * assignment.getCourseId(),"1"); //所有活动 Map<String,Object> res=new
	 * HashMap<String, Object>(); List<Activity>
	 * activities=activityDao.findActivityByAssignmentId(assignment.getId()); for
	 * (int i = 0; i < activities.size(); i++) { for (int j = 0; j <
	 * courseStudents.size(); j++) { //padId activityId userid List<SentenceClass>
	 * resSentences=new ArrayList<SentenceClass>();//存储学生的反思句子类别 String
	 * padId=courseStudents.get(j).getGroupId()+"$"+assignment.getAssignmentName();
	 * List<SentenceClass> sentences =
	 * stcDao.findByPadIdAndActivityId(padId,activities.get(i).getId()); if
	 * (sentences.size() > 0){ //1学生 写了 而且按过按钮，系统至少有一个版本，直接查询 String lastVersion =
	 * sentences.get(0).getVersionNum(); for (int k = 0; k < sentences.size(); k++)
	 * { if (Integer.parseInt(sentences.get(k).getVersionNum()) >
	 * Integer.parseInt(lastVersion)) { lastVersion =
	 * sentences.get(k).getVersionNum(); } } for (int k = 0; k <
	 * sentences.size();k++) { if
	 * (sentences.get(k).getVersionNum().equals(lastVersion)) {
	 * resSentences.add(sentences.get(k)); } } }else { //2
	 * 学生写了，没按过按钮，系统没有版本，调用etherpad和句子分类工具进行分类。 （学生没写情况也是这样） Map<String, Object>
	 * pdTmap = new HashMap<String, Object>(); pdTmap =
	 * epliteClient.getText(padId);// getText默认返回最新版本的 text String docText =
	 * (String) pdTmap.get("text"); List<Map<String, Object>> versions =
	 * epliteClient.getAllRevisions(padId); // 2.2 保存最后一个版本号 String padLastVersion =
	 * Integer.toString((Integer) versions.get(versions.size() - 1).get("revs")); //
	 * classInfo [[0, self_critique, 自我批判, 反思自己的不足], sentenceInfo 所有句子信息 Map<String,
	 * Object> sentenceClassInfo =
	 * DocToSentencesClassUtil.docSentenceClass(docText); // 所有句子信息
	 * {sentence：句子内容，class= 中文 标签} List<Map<String, Object>> sentencesInfo =
	 * (List<Map<String, Object>>) sentenceClassInfo.get("sentenceInfo"); //
	 * 保存每条句子信息 for (int k = 0; k < sentencesInfo.size(); k++) { SentenceClass
	 * sentence = new SentenceClass();// id自动生成 uuid 不创建
	 * sentence.setContent(sentencesInfo.get(k).get("sentence").toString());
	 * sentence.setSentenceClass(sentencesInfo.get(k).get("class").toString());
	 * sentence.setVersionNum(padLastVersion); sentence.setMarker("cpu");
	 * sentence.setPadId(padId);
	 * sentence.setStuId(courseStudents.get(j).getUserId());
	 * sentence.setActivityId(activities.get(i).getId());
	 * resSentences.add(sentence); } }
	 * 
	 * //存储学生信息 } } System.out.println("edn"); return res; }
	 */
	

	//获得班级 某次作业下同学们的反思写作参考分数 ，在前端导出为excel表 //无法很好解决activity最新版本问题 ，直接每次都访问etherpad最新版text，调用句子分类算法
	//该算法有待优化，应当尽力去查询，而不是每次都访问etherpad再次分类
	@Override
	public List<Map<String, String>> getCourseRftAsmtRferScores(Assignment assignment) throws Exception {
		//1列出所有学生 班级学查询条件 班级id 小组类型 1 （代表个人作业）| 因为本功能针对反思写作，反思写作作业都是个人作业 
		List<CourseGroupUser> courseStudents=courseGroupUserDao.findCourseGroupUserByCourseIdAndGroupType(assignment.getCourseId(),"1");
		List<List<String>> classIndexAndValues = DocToSentencesClassUtil.getClassInfos();// 存 句子 类别 下标 和 名称 等具体信息
		List<SentenceClass> resSentences = new ArrayList<SentenceClass>();// 存储所有学生的句子信息
		//获取所有学生 文章 句子类别信息  最新的
		List<Map<String, String>> resMaps=new ArrayList<Map<String,String>>();//返回结果
		for (int i = 0; i < courseStudents.size(); i++) {
			Map<String, String> resMap=new HashMap<String, String>();
			User stu=userDao.findOne(courseStudents.get(i).getUserId());
			resMap.put("stuNum",stu.getUsername());//存储学号
			resMap.put("name",stu.getRealname());//姓名 
			resMap.put("stuId",stu.getId());//学生id
			String padId=courseStudents.get(i).getGroupId()+"$"+assignment.getAssignmentName();
			Map<String, Object> pdTmap = new HashMap<String, Object>();
			pdTmap = epliteClient.getText(padId);// getText默认返回最新版本的 text
			String docText = (String) pdTmap.get("text");
			 //1  去空格 回车 换行 制表符
		    Pattern p = Pattern.compile("\\s*|\t|\r|\n");
		    Matcher m = p.matcher(docText);
		    docText = m.replaceAll("");
		    docText=docText.replace(",","，");//替换英文,避免csv换行
			resMap.put("docText",docText);//学生的文章内容
			// classInfo [[0, self_critique, 自我批判, 反思自己的不足], sentenceInfo 所有句子信息
			Map<String, Object> sentenceClassInfo = DocToSentencesClassUtil.docSentenceClass(docText);
			List<Map<String, Object>> sentencesInfo = (List<Map<String, Object>>) sentenceClassInfo.get("sentenceInfo");
			// 保存每条句子信息
			for (int j = 0; j < sentencesInfo.size(); j++) {
				SentenceClass sentence = new SentenceClass();// id自动生成 uuid 不创建
				sentence.setContent(sentencesInfo.get(j).get("sentence").toString());
				sentence.setSentenceClass(sentencesInfo.get(j).get("class").toString());
				sentence.setVersionNum("0");
				sentence.setMarker("cpu");
				sentence.setPadId(padId);
				sentence.setStuId(courseStudents.get(i).getUserId());
				sentence.setActivityId("0");
				resSentences.add(sentence);
			}
			resMaps.add(resMap);
		}
		//给每个学生句子类别设置初始值  0
		for (int i = 0; i < resMaps.size(); i++) {
			for (int j = 0; j < classIndexAndValues.size(); j++) {
				if (!classIndexAndValues.get(j).get(2).equals("其他")) {
					resMaps.get(i).put(classIndexAndValues.get(j).get(2),"0");
				}
			}
		}
	   //计算每个类别数量 并且赋值
		for (int i = 0; i < resMaps.size(); i++) {
			for (int j = 0; j < resSentences.size(); j++) {
				if (resMaps.get(i).get("stuId").equals(resSentences.get(j).getStuId())) {//一个学生的句子
					if (!resSentences.get(j).getSentenceClass().equals("其他")) {
						resMaps.get(i).put(resSentences.get(j).getSentenceClass(),Integer.toString(Integer.parseInt(resMaps.get(i).get(resSentences.get(j).getSentenceClass()))+1));
					}
				}
			}
		}
		//给出参考分数
		for(int i = 0; i < resMaps.size(); i++) {
			double score=0;//默认初始值为0
			for (Map.Entry<String,String> entry : resMaps.get(i).entrySet()) {
	            for (int j = 0; j < classIndexAndValues.size(); j++) {
					if (entry.getKey().equals(classIndexAndValues.get(j).get(2))) {
						if (Integer.parseInt(entry.getValue())>=3){//给2
							score=score+10;
						}else if (Integer.parseInt(entry.getValue())==0) {//给0
							score=score+0;
						}else {// 0-3 给1
							score=score+5;
						}
					}
				}
	        }
			resMaps.get(i).put("score",String.valueOf(Math.round(score*1.25)));
		}
		
		
		
//		  for (int i = 0; i < resMaps.size(); i++) {
//		  System.out.println(resMaps.get(i).toString()); 
//		  }
		 
		 		 
        return resMaps;
	}
    
	//导出学生 对反馈的评价 打分，感受 ，以版本记录
	@Override
	public Map<String,Object> getStuFbContents(Assignment assignment) {
		// 1 列出所有学生 班级学查询条件 班级id 小组类型 1 （代表个人作业）| 因为本功能针对反思写作，反思写作作业都是个人作业 
		Map<String,Object> resMap=new HashMap<String, Object>();
		List<CourseGroupUser> courseStudents=courseGroupUserDao.findCourseGroupUserByCourseIdAndGroupType(assignment.getCourseId(),"1");
		List<Map<String, String>> stufbContens=new ArrayList<Map<String,String>>();//返回结果
		List<List<String>> classIndexAndValues = DocToSentencesClassUtil.getClassInfos();// 存 句子 类别 下标 和 名称 等具体信息
		// 2 构建表头
		List<RftFeedbackItem> fbitems=rftFbItemDao.findByTemplateId(assignment.getRftFbTptId());
		List<String> headNames=new ArrayList<String>();//前三个 stuNum,Name,VersionNum,
		headNames.add("学号");
		headNames.add("姓名");
		headNames.add("版本号");
		Map<String, String> cmpfbNamesMap=new HashMap<String, String>();//暂存结果
		Map<String, String> vainfbNamesMap=new HashMap<String, String>();
		for (int i = 0; i < fbitems.size(); i++) {
			if (fbitems.get(i).getValuence().equals("0")) {//负反馈
				headNames.add(fbitems.get(i).getClassName()+"_负反馈");
				cmpfbNamesMap.put(fbitems.get(i).getId(),fbitems.get(i).getClassName()+"_负反馈");
				vainfbNamesMap.put(fbitems.get(i).getClassName()+"_负反馈","未产生该类别的反馈");
			}else if (fbitems.get(i).getValuence().equals("1")) {//正反馈
				headNames.add(fbitems.get(i).getClassName()+"_正反馈");
				cmpfbNamesMap.put(fbitems.get(i).getId(),fbitems.get(i).getClassName()+"_正反馈");
				vainfbNamesMap.put(fbitems.get(i).getClassName()+"_正反馈","未产生该类别的反馈");
			}else {//感受或者思考  只要不是1和0
				headNames.add(fbitems.get(i).getClassName());
				cmpfbNamesMap.put(fbitems.get(i).getId(),fbitems.get(i).getClassName());
				vainfbNamesMap.put(fbitems.get(i).getClassName(),"未操作");
			}
	   }
		resMap.put("heads", headNames);
	   // 3  添加每个学生的 反馈内容相关信息，每个学生 按照版本分行记录
	   for (int i = 0; i < courseStudents.size(); i++) {
  		   String stuId=courseStudents.get(i).getUserId();
  		   User stu=userDao.findOne(stuId);
		   List<RftFbItemScore> stuRftFbItemScores=rftFbItemScoreDao.findByAssignmentIdAndStuId(assignment.getId(),stuId);
		   if (stuRftFbItemScores.size()>0) {//说明学生至少 对一个反馈进行了交互
			   Map<String,String> versionMap=new HashMap<String, String>();//存版本号
			   for (int j = 0; j < stuRftFbItemScores.size(); j++) {
				   versionMap.put(stuRftFbItemScores.get(j).getVersionNum(),"0");//问题行   debug！！！！！！！！
			   }
			   for (String versionNum : versionMap.keySet()) {//按照版本号遍历map了
				    Map<String, String> tmpvainfbNamesMap=new HashMap<String, String>();
				    //构建 每行数据的空map
				    for (Entry<String, String> entry:vainfbNamesMap.entrySet()) {
				    	tmpvainfbNamesMap.put(entry.getKey(),entry.getValue());
				    } 
				    //判断 每行map的 维度有没有生成反馈
				    //计算每个class的比例  构建一个比例 map
					Map<String,String> classProportion=new HashMap<String, String>();
				    List<SentenceClass> sentences=stcDao.findByPadIdAndVersionNum(courseStudents.get(i).getGroupId()+"$"+assignment.getAssignmentName(),versionNum);
				    for (int j = 0; j < classIndexAndValues.size();j++) {
						classProportion.put(classIndexAndValues.get(j).get(2),"0");//初始 比例为0
					}
					int sentenceCount=sentences.size();//句子总数
					for (int j = 0; j < sentences.size(); j++) {
						classProportion.put(sentences.get(j).getSentenceClass(),Integer.toString(Integer.parseInt(classProportion.get(sentences.get(j).getSentenceClass()))+1));
					}
					//遍历 map 设置比值
					// 创建一个数值格式化对象   
					NumberFormat numberFormat = NumberFormat.getInstance();   
					// 设置精确到小数点后2位   
					numberFormat.setMaximumFractionDigits(2);   
					for (String key : classProportion.keySet()) {
						int classNum=Integer.parseInt(classProportion.get(key));//该类别句子数量
						String result = numberFormat.format((float)classNum/(float)sentenceCount*100);
						classProportion.put(key,result);
				    }
					 Map<String,String> midMap=new HashMap<String, String>();
					 double flag=11;
					 for (Entry<String,String> entry : classProportion.entrySet()) {
						 if (!entry.getKey().equals("其他")) {
							if (Double.parseDouble(entry.getValue())>flag){//正向反馈
								midMap.put(entry.getKey()+"_正反馈","未操作");
							}else{//负向反馈
								midMap.put(entry.getKey()+"_负反馈","未操作");
							}
						}
					 }
					 for (Entry<String,String> entry : midMap.entrySet()) {
						 tmpvainfbNamesMap.put(entry.getKey(),entry.getValue());//找到产生的反馈类别，并且用未操作替换 未产生
					 }
				    //end
				    Map<String,RftFbItemScore> tempForMap=new HashMap<String, RftFbItemScore>();
				    tmpvainfbNamesMap.put("学号", stu.getUsername());
				    tmpvainfbNamesMap.put("姓名", stu.getRealname());
				    tmpvainfbNamesMap.put("版本号",versionNum);
				    for(int j = 0; j < stuRftFbItemScores.size(); j++) {
				    	if (stuRftFbItemScores.get(j).getVersionNum().equals(versionNum)){
							tempForMap.put(stuRftFbItemScores.get(j).getDimId(),stuRftFbItemScores.get(j));
						}
					} 
				    for (Entry<String, RftFbItemScore> entry : tempForMap.entrySet()) {
			            for (int j = 0; j < stuRftFbItemScores.size(); j++) {
							if (stuRftFbItemScores.get(j).getDimId().equals(entry.getKey())&&stuRftFbItemScores.get(j).getVersionNum().equals(versionNum)){
								if (stuRftFbItemScores.get(j).getTimeStamp().compareTo(entry.getValue().getTimeStamp())>0){
									tempForMap.put(stuRftFbItemScores.get(j).getDimId(),stuRftFbItemScores.get(j));
								}
							}
						}
			        }
				    for (Entry<String,RftFbItemScore> entry:tempForMap.entrySet()) {
				    	
				    	if (entry.getValue().getDimName().equals("感受")) {
				    		tmpvainfbNamesMap.put(cmpfbNamesMap.get(entry.getKey()),entry.getValue().getFeeling());
						}else {
							//思考，考虑到有可能出现英文逗号 导致csv 不正常换行，所以替换 为中文逗号
							String thinking=entry.getValue().getScore();
							thinking=thinking.replace(",","，");
							tmpvainfbNamesMap.put(cmpfbNamesMap.get(entry.getKey()),thinking);
						}
				    	
				    }
				    stufbContens.add(tmpvainfbNamesMap);    
		       }
		   } 
	   }
	   resMap.put("stuFbContents", stufbContens);
	   return resMap;
	}
    
	//句子修改信息
	@Override
	public Map<String, Object> getSentenceModifiedInfo(Assignment assignment) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		//1列出所有学生 班级学查询条件 班级id 小组类型 1 （代表个人作业）| 因为本功能针对反思写作，反思写作作业都是个人作业 
		List<Map<String,String>> allLines=new ArrayList<Map<String,String>>();
		//表头 学号	 姓名	句子id  文档id 	句子内容		句子修改前类别	句子修改后类别	版本号	修改时间
        List<String> heads=new ArrayList<String>();
        heads.add("学号");
        heads.add("姓名");
        heads.add("文章id");
        heads.add("版本号");
        heads.add("句子id");
        heads.add("句子内容");
        heads.add("句子修改前类别");
        heads.add("句子修改后类别");
        heads.add("修改时间");
        resMap.put("heads", heads);
		//应该先找到这个班级 作业下所有 修改后的句子，按照句子遍历储存信息
        List<Activity> activities=activityDao.findActivityByAssignmentId(assignment.getId());
        for (int i = 0; i < activities.size(); i++) {
			List<ModifiedSentence> modifiedSentences=modifiedSentenceDao.findByActivityId(activities.get(i).getId());
			for (int j = 0; j < modifiedSentences.size(); j++) {//存储每行数据
				Map<String,String> lineMap=new HashMap<String, String>();
				User stu=userDao.findOne(modifiedSentences.get(j).getUserId());
				lineMap.put(heads.get(0),stu.getUsername());
				lineMap.put(heads.get(1),stu.getRealname());
				SentenceClass sentence=sentenceClassDao.findOne(modifiedSentences.get(j).getInitialSentenceId());
				lineMap.put(heads.get(2),sentence.getPadId());//文章 id
				lineMap.put(heads.get(3),modifiedSentences.get(j).getVersionNum());
				lineMap.put(heads.get(4),modifiedSentences.get(j).getInitialSentenceId());//句子id
				String sentenceContent=sentence.getContent();//句子内容可能有英文 逗号 ,  影响 csv导出，所以全部替换为中文 ，
				sentenceContent=sentenceContent.replace(",","，");
				lineMap.put(heads.get(5),sentenceContent);
				lineMap.put(heads.get(6),modifiedSentences.get(j).getSentenceClassBefore());
				lineMap.put(heads.get(7),modifiedSentences.get(j).getSentenceClassAfter());
				lineMap.put(heads.get(8),modifiedSentences.get(j).getModifyTime());
				allLines.add(lineMap);
			}
		}
       
        resMap.put("modifiedSentenceInfo", allLines);
		return resMap;
	}
    
	//反馈得分图信息    最大 最小 平均  不再调用
	@Override
	public Map<String, Object> getRftItemScoreInfo(Assignment assignment) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		Course course=courseDao.findOne(assignment.getCourseId());
		resMap.put("courseInfo", course);
		//1存储 反思类别  横坐标  8 个 反思类别
		Map<String,List<String>> scoreMap=new HashMap<String, List<String>>();
		Map<String,List<String>> detailScoreMap=new HashMap<String, List<String>>();//存每个维度所有得分
	    Map<String,String> itemNames=new HashMap<String, String>();//存储横轴 反思句子类别 名称
		String rftItemId=assignment.getRftFbTptId();
		List<RftFeedbackItem> rftFbItems=rftFbItemDao.findByTemplateId(rftItemId);
	    for (RftFeedbackItem rftFeedbackItem : rftFbItems) {
	        if (rftFeedbackItem.getValuence().equals("0")||rftFeedbackItem.getValuence().equals("1")) {
	        	List<String> itemInfo=new ArrayList<String>();
	        	List<String> scores=new ArrayList<String>();
	        	itemInfo.add(rftFeedbackItem.getClassName());//名称
	        	itemInfo.add(rftFeedbackItem.getValuence());//正负性
	        	
	        	scoreMap.put(rftFeedbackItem.getId(),itemInfo);
	        	itemNames.put(rftFeedbackItem.getClassName(),"0");
	        	detailScoreMap.put(rftFeedbackItem.getId(),scores);
			}
		}
	    resMap.put("className", itemNames);
	    //2获取得分
	    List<Activity> activities=activityDao.findActivityByAssignmentId(assignment.getId()); 
	    for (Entry<String, List<String>> entry:scoreMap.entrySet()) {
	    	String dimId=entry.getKey();//某个反馈的 id
			List<String> dimScores=new ArrayList<String>();
			  for (Activity activity : activities) {
				List<RftFbItemScore> rftFbItemScores=rftFbItemScoreDao.findByActivityId(activity.getId());
				for (RftFbItemScore rftFbItemScore : rftFbItemScores) {
					if (rftFbItemScore.getDimId().equals(dimId)){//dimId 只可能正负性1或者0 所以不用担心 score记录情感或者思考
						dimScores.add(rftFbItemScore.getScore());
					}
				}
			  }
			 detailScoreMap.put(dimId,dimScores);//反思类别id  ， 【分数，，，】 
	    }
	    //3 遍历 得分 map 计算最大值 ，平均值，最小值    
	    for (Entry<String, List<String>> entry:detailScoreMap.entrySet()) {
	    	String dimId=entry.getKey();
	    	List<String> scores=entry.getValue();
	    	List<String> scoreInfos=scoreMap.get(dimId);
	    	int count=scores.size();
	    	if (count==0) {//说明 该反馈没有被打分 ， 3个值全部为0
	    		scoreInfos.add("0");//最小值
	    		scoreInfos.add("0");//平均值
	    		scoreInfos.add("0");//最大值
			}else if (count==1) {//三个值相同
				scoreInfos.add(scores.get(0));
				scoreInfos.add(scores.get(0));
				scoreInfos.add(scores.get(0));	
			}else {
				int min=Integer.parseInt(scores.get(0));
				int max=Integer.parseInt(scores.get(0));//最大与最小都赋第一个值
				int sum=0;
				for (int i = 0; i < scores.size(); i++) {
					sum=sum+Integer.parseInt(scores.get(i));//计算总分数
					if (min>Integer.parseInt(scores.get(i))) {
						min=Integer.parseInt(scores.get(i));
					}
					if (max<Integer.parseInt(scores.get(i))) {
						max=Integer.parseInt(scores.get(i));
					}
				}
				DecimalFormat df = new DecimalFormat("0.00");//格式化小数  
				String mean = df.format((float)sum/count);//返回的是String类型 
				scoreInfos.add(Integer.toString(min));//最小值
				scoreInfos.add(mean);//平均值	
				scoreInfos.add(Integer.toString(max));//最大值
			}
	    	scoreMap.put(dimId,scoreInfos);//将分数信息 替换进入map
	    }
	    resMap.put("score",scoreMap);
	   // System .out.println(resMap.toString());
		return resMap;
	}
     
	//反馈得分图信息
	@Override
	public Map<String, Object> getRftScoreFigInfo(Assignment assignment) {
		Map<String, Object> resMap=new HashMap<String, Object>();
		Course course=courseDao.findOne(assignment.getCourseId());
		resMap.put("courseInfo", course);
		//准备 接受数据类型
		String rftItemId=assignment.getRftFbTptId();
		List<RftFeedbackItem> rftFbItems=rftFbItemDao.findByTemplateId(rftItemId);
		Map<String,List<String>> scoreMap=new HashMap<String, List<String>>();
		Map<String,List<String>> detailScoreMap=new HashMap<String, List<String>>();//存每个维度所有得分
		 for (RftFeedbackItem rftFeedbackItem : rftFbItems) {
		        if (rftFeedbackItem.getValuence().equals("0")||rftFeedbackItem.getValuence().equals("1")) {
		        	List<String> scores=new ArrayList<String>();
		        	List<String> itemInfo=new ArrayList<String>();
		        	itemInfo.add(rftFeedbackItem.getClassName());//名称
		        	itemInfo.add(rftFeedbackItem.getValuence());//正负性
		        	scoreMap.put(rftFeedbackItem.getId(),itemInfo);
		        	detailScoreMap.put(rftFeedbackItem.getId(),scores);
				}
			}
		//1存储 反思类别  横坐标  8 个 反思类别
		List<String> classNames=new ArrayList<String>();
		List<List<String>> classInfo=DocToSentencesClassUtil.getClassInfos();
		for (int i = 0; i < classInfo.size(); i++) {
			for (int j = 0; j < classInfo.size(); j++) {
				if(classInfo.get(j).get(5).equals(Integer.toString(i))&&(!classInfo.get(j).get(2).equals("其他"))){
					classNames.add(classInfo.get(j).get(2));//按顺序添加 名称
				}
			}
		}
		resMap.put("className",classNames);
		//2添加2中类型 的盒子名称
		List<String> rftType=new ArrayList<String>();
		rftType.add("正向反馈");
		rftType.add("负向反馈");
		resMap.put("rftType",rftType);
		//3获取得分
	    List<Activity> activities=activityDao.findActivityByAssignmentId(assignment.getId()); 
	    for (Entry<String, List<String>> entry:scoreMap.entrySet()) {
	    	String dimId=entry.getKey();//某个反馈的 id
			List<String> dimScores=new ArrayList<String>();
			  for (Activity activity : activities) {
				List<RftFbItemScore> rftFbItemScores=rftFbItemScoreDao.findByActivityId(activity.getId());
				for (RftFbItemScore rftFbItemScore : rftFbItemScores) {
					if (rftFbItemScore.getDimId().equals(dimId)){//dimId 只可能正负性1或者0 所以不用担心 score记录情感或者思考
						dimScores.add(rftFbItemScore.getScore());
					}
				}
			  }
			 detailScoreMap.put(dimId,dimScores);//反思类别id  ， 【分数，，，】 
	    }  
	  //4构造两个盒子数据
	    Map<String,List<List<String>>> serisData=new HashMap<String,List<List<String>>>();
	    for (int i = 0; i < rftType.size(); i++) {
	    	List<List<String>> boxData=new ArrayList<List<String>>();
			if (rftType.get(i).equals("正向反馈")){//按照顺序构造所类别的正向得分
				for (int j = 0; j < classNames.size(); j++) {
					  for (Entry<String, List<String>> entry:detailScoreMap.entrySet()) {
						  RftFeedbackItem rftfbItem=rftFbItemDao.findOne(entry.getKey());
						  if (rftfbItem.getClassName().equals(classNames.get(j))&&rftfbItem.getValuence().equals("1")){
							  if (entry.getValue().size()==0) {
								  entry.getValue().add("0");//至少加一个0
							  }
							  boxData.add(entry.getValue());
						  }
					  }
				}
			}else {
				//按照顺序构造所类别的正向得分
				for (int j = 0; j < classNames.size(); j++) {
					  for (Entry<String, List<String>> entry:detailScoreMap.entrySet()) {
						  RftFeedbackItem rftfbItem=rftFbItemDao.findOne(entry.getKey());
						  if (rftfbItem.getClassName().equals(classNames.get(j))&&rftfbItem.getValuence().equals("0")){
							  if (entry.getValue().size()==0) {
								  entry.getValue().add("0");//至少加一个0
							  }
							  boxData.add(entry.getValue());
						  }
					  }
				}
			}
			serisData.put(rftType.get(i),boxData);
		}
		resMap.put("serisData", serisData);
		//5找最大值最小值
		int maxScore=0;
		int minScore=0;
	  for (Entry<String, List<String>> entry:detailScoreMap.entrySet()){
		  List<String> socres=entry.getValue();
		  for (int i = 0; i < socres.size(); i++){
			  		if (maxScore<Integer.parseInt(socres.get(i))) {
			  			maxScore=Integer.parseInt(socres.get(i));
					}
			  		if (minScore>Integer.parseInt(socres.get(i))) {
			  			minScore=Integer.parseInt(socres.get(i));
					}
		  }
	  }
		resMap.put("maxScore", maxScore);
		resMap.put("minScore", minScore);
		//System.out.println(resMap.toString());
		return resMap;
	}
    
	
	//返回作业参考分 csv文件名称
	@Override
	public String getCsvName(String assignmentId) {
		Assignment assignment=assignmentDao.findOne(assignmentId);
		String courseName=" ";//课程名称
	    courseName=courseDao.findOne(assignment.getCourseId()).getCourseName();
	    String csvName=courseName+"_"+assignment.getAssignmentName()+"作业"+".csv";
		return csvName;
	}
   
			
			
		
	
}